package com.jdk.thread.lock2;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

/**
 * @Description :
 * @FileName: ThreadTest1.java
 * @Author :WeiHui.Zhang
 * @Data : 2016年2月1日 下午2:55:00
 * @Version:V1.00
 */
public class ThreadTest3 extends Thread {

	@Override
	public void run() {
		exec();
	}

	public static synchronized void exec() {
		try {
			FileOutputStream fileOutputStream = new FileOutputStream("C:/" + Thread.currentThread().getName() + ".txt");
			for (int i = 1; i < 10000; i++) {
				String data = "No." + Thread.currentThread().getName() + ":" + i;
				PrintStream out = new PrintStream(fileOutputStream);
				System.setOut(out);
				System.out.println(data);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) throws InterruptedException {
		for (int i = 0; i < 10; i++) {
			new ThreadTest3().start();
			Thread.sleep(1);
		}
	}
}
